#ifndef _RETRO_CONTAINER
#define _RETRO_CONTAINER

#define TITLEBOX_HEIGHT     20

namespace Retro
{
  namespace Creator
  {
    namespace GUI
    {
      class Container : public Windows::Window
      {
      private:
        enum ContainerState
        {
          StateNormal,
          StateOver,
          StateCloseOver,
          StateCloseDown,
          StateGrab,
          StateDrag
        };

        BOOL            mCollapsed;
        INT             mOldHeight;
        Geom::Point     mPoint;
        BOOL            mResize;
        ContainerState  mState;
        BOOL            mCloseable;
        BOOL            mDraggable;
        BOOL            mActive;
        LayoutElement   mLayout;
        HWND            mContent;
        Gdip::Bitmap*   mBuffer;

        VOID  invalidateClose();
        VOID  getCloseBounds(LONG cx, Geom::Bounds &bounds);

      protected:
        virtual VOID  onCreate(Event::WndCreateEvent& iEvent);
        virtual VOID  onDestroy();
        virtual VOID  onSize(Event::SizeEvent& iEvent);
        virtual VOID  onPaint();
        virtual VOID  onEraseBackground(Event::EraseBackgroundEvent& iEvent);
        virtual VOID  onMouseDown(Event::MouseEvent& iEvent);
        virtual VOID  onMouseUp(Event::MouseEvent& iEvent);
        virtual VOID  onMouseMove(Event::MouseEvent& iEvent);
        virtual VOID  onMouseLeave();

      public:
        VOID  invalidateHeader()
        {
          Geom::Rect client = getClient();
          client.bottom = TITLEBOX_HEIGHT;
          invalidate(client);
        };

        INL BOOL  getCollapsed()
        {
          return mCollapsed;
        }
        VOID      setCollapsed(BOOL value);

        INL BOOL  getDraggable()
        {
          return mDraggable;
        }
        INL VOID  setDraggable(BOOL value)
        {
          mDraggable = value;
        }

        INL BOOL  getCloseable()
        {
          return mCloseable;
        }
        INL VOID  setCloseable(BOOL value)
        {
          mCloseable = value;
        }

        INL BOOL  geActive()
        {
          return mActive;
        }
        VOID      setActive(BOOL value);

        INL LayoutElement*  getLayout()
        {
          return &mLayout;
        }

        INL VOID  setChild(HWND value)
        {
          mLayout.clear();
          mLayout.addFill(mContent = value);
        }

        INL HWND            getContent()
        {
          return mContent;
        }
        INL VOID            setContent(HWND value)
        {
          mContent = value;
        }

        VOID                doLayout();

        Container();
      };
    } // namespace GUI
  } // namespace Creator
} // namespace Retro

#endif